<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib prefix="s" uri="/struts-tags"%>
<%@ page import="com.onlineMIS.ORM.entity.headQ.user.*,java.util.Date,java.text.SimpleDateFormat"%>
<%@ page import="com.onlineMIS.ORM.entity.headQ.supplier.purchase.PurchaseOrder"%>
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>查询采购单据</title>
<%@ include file="../../../common/Style.jsp"%>

<script>
$(document).ready(function(){
	parent.$.messager.progress('close'); 

	var params = $.serializeObject($('#inventorySearchForm'));
	
	$('#dataGrid').datagrid({
		url : 'supplierPurchaseJSON!searchPurchaseOrder',
		queryParams: params,
		fit : true,
		border : false,
		checkOnSelect : false,
		selectOnCheck : false,
		singleSelect:true,
		nowrap : false,
		showFooter:true,
		rowStyler: function(index,row){
			var style = "";
			if (row.status == 1)
				style += 'color:blue;';
			else if (row.status == 3)
				style += 'color:red;';

			if (row.type == 1)
				style += 'background-color:#F9F8FA;';
			return style;
		},
		columns : [ [ {
			field : 'id',
			title : '编号',
			width : 50
		}, {
			field : 'supplier',
			title : '供应商名称',
			width : 120
				
		}, {
			field : 'creationTime',
			title : '创建时间',
			width : 125
		},  
		 {
			field : 'storeName',
			title : '录入库房',
			width : 60
		},{
			field : 'orderAuditor',
			title : '录入会计',
			width : 60
		}, {
			field : 'totalQuantity',
			title : '总数',
			width : 60
		}, {
			field : 'totalRecCost',
			title : '进价总额',
			width : 70,
			formatter: function (value, row, index){
				return parseNumberValue(row.totalRecCost);
			}
		},	{			
			field : 'totalWholePrice',
			title : '批发总额',
			width : 80,
			formatter: function (value, row, index){
				return parseNumberValue(row.totalWholePrice);
			}
		}, {
			field : 'comment',
			title : '备注',
			width : 330,
			formatter: function(value) {
				  return '<div class="datagrid-cell" title="' + value + '">' + value + '</div>';
        }
		}, {
			field : 'type',
			title : '单据类型',
			width : 110,
			align: 'center',
			formatter :  function(value, row, index) {
				if(row.id == 0){
					var str = "";
				}else if(row.type == <%=PurchaseOrder.TYPE_PURCHASE%>){
					var str = $.formatString('<button class="button7">采购入库单</button>');
				}else if(row.type == <%=PurchaseOrder.TYPE_RETURN%>){
					var str = $.formatString('<button class="button8">采购退货单</button>');
				}else if(row.type == <%=PurchaseOrder.TYPE_FREE%>){
					var str = $.formatString('<button class="button9">采购赠送单</button>');
				}
				return str;
			}
		}, {	
			field : 'statusS',
			title : '状态',
			width : 70
		}, {
			field : 'lastUpdateTime',
			title : '最后更新时间',
			width : 125
		},{
			field : 'exportNum',
			title : '导精算',
			width : 50
		}, {	
			field : 'action',
			title : '查看/修改',
			width : 70,
			align: 'center',
			formatter : function(value, row, index) {
				var str = '';
				
				if (row.id != 0){
				   var url = "<%=request.getContextPath()%>/action/supplierPurchaseJSP!getPurchaseOrder?formBean.order.id=" + row.id;
					   str += $.formatString('<a href="#" onclick="addTab6(\'{0}\',\'{1}\');"><img border="0" src="{2}" title="修改"/></a>', url, '采购单据 ' + row.id,'<%=request.getContextPath()%>/conf_files/easyUI/themes/icons/update.png');
				}
				return str;
			}
		}]],
        onLoadSuccess: function(data) {
	        var tr = $(this).datagrid('getPanel').find('div.datagrid-body tr');
	        tr.each(function() {
	            $(this).children('td').children('div').css('height', '32px');
	        });
	    	 // 设置数据行垂直居中
	        $(this).datagrid('getPanel').find('.datagrid-body .datagrid-cell').css({
	            'display': 'flex',
	            'align-items': 'center'
	        });
	        $('.datagrid-cell').tooltip({
	            position: 'bottom',
	            onShow: function() {
	                $(this).tooltip('tip').css('max-width', '500px'); // 自定义宽度
	            }
	        });
	    },
		toolbar : '#toolbar',
	});
});

function searchOrder(){
	var params = $.serializeObject($('#inventorySearchForm')); 
	$('#dataGrid').datagrid('load',params); 
}

function downloadOrderInfos(){
	document.inventorySearchForm.action="supplierPurchaseJSP!downloadOrderInfos";
	document.inventorySearchForm.submit();
}

function searchOrderById(){
	var orderId = $("#orderID").val();
	if(orderId == "" || orderId == null){
		$.messager.alert('提示', '请输入单据号,单据号不能为空', 'warning');
	}else{
		let isNum = is_number(orderId);
		if(isNum){
			searchOrder();
		}else{
			$.messager.alert('提示', '非法输入，请输入正确的单据号', 'warning');
		}		
	}
}
</script>

</head>
<body>
	<div class="easyui-layout" data-options="fit : true,border : false">
	
 <div data-options="region:'north',border:false" style="height: 130px;">
	<s:form id="inventorySearchForm" name="inventorySearchForm" action="/action/inventoryOrder!search"
		theme="simple" method="POST"> 
		<table width="98%" align="center" class="OuterTable">
			<tr>
				<td>
					<table width="100%" border="0">
						<tr>
							<td height="50" colspan="7">
								<div class="errorAndmes">
									<s:actionerror cssStyle="color:red" />
									<s:actionmessage cssStyle="color:blue" />
								</div>
								<table width="100%" border="0">
									<tr class="PBAOuterTableTitale">
										<td height="35" colspan="10">总部采购单据:
										</td>
									</tr>						

									<tr class="InnerTableContent">
										<td width="15%" rowspan="2"><%@ include file="../SupplierInput.jsp"%></td>
										<td width="4%" align="center"><strong>创建时间：</strong></td>
										<td width="17%"><s:textfield id="startDate"
												name="formBean.searchStartTime" cssClass="easyui-datebox"
												data-options="width:90,editable:false" /> &nbsp;至 &nbsp; <s:textfield
												id="endDate" name="formBean.searchEndTime"
												cssClass="easyui-datebox"
												data-options="width:90,editable:false" /></td>
										<td width="4%" align="center"><strong>包含货品：</strong></td> 
				 						<td width="15%"><%@ include file="../../common/ProductCodeInput.jsp"%> </td>		
										<td width="4%" align="center"><strong>单据号：</strong></td>
										<td width="23%">
											<s:textfield cssClass="easyui-searchbox" id="orderID" data-options="prompt:'请输入单据号',searcher:searchOrderById" name="formBean.order.orderId"  size="20" />
										</td>
									</tr>
									
									<tr>
										<td align="center"><strong>单据种类：</strong></td>
										<td ><s:select name="formBean.order.type" cssClass="easyui-combobox" style="width:120px;text-align: center"
												id="orderType" list="formBean.order.typeHQMap" listKey="key"
												listValue="value" headerKey="-1" headerValue="----全部类别----" />
											 <s:select name="formBean.belongTo" cssClass="easyui-combobox" style="width:120px;text-align: center"
												id="orderType" list="formBean.belongToMap" listKey="key"
												listValue="value" headerKey="-1" headerValue="----全部单据----" />							
												</td>
										<td align="center"><strong>状态：</strong></td>
										<td><s:select name="formBean.order.status" cssClass="easyui-combobox" style="width:120px;text-align: center"
												id="orderStatus" list="formBean.order.statusMap" listKey="key"
												listValue="value" headerKey="-1" headerValue="----全部状态----" /></td>
									   
										<td align="center" ><strong>备注：</strong></td>
										<td><s:textfield id="comment" cssClass="easyui-textbox" data-options="prompt:'请输入单据摘要'"
												name="formBean.order.comment" size="20" /></td>
										
					
				            			</td>
									</tr>
								</table>
							</td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
		</s:form>
	</div>
		
		<div data-options="region:'center',border:false" >
			<table id="dataGrid" border="0">
			</table>
			<div id="toolbar" style="display: none;" >
				<a onclick="searchOrder();" href="javascript:void(0);"
					class="easyui-linkbutton"
					data-options="iconCls:'icon-search',plain:true">查询单据</a>
					<a onclick="downloadOrderInfos();" href="javascript:void(0);"
					class="easyui-linkbutton"
					data-options="iconCls:'icon-print',plain:true">下载单据</a> 
			</div>
		</div>
	</div>

</body>
</html>